package cn.com.scitc.servlet.paid;

import cn.com.scitc.dao.PaidDao;
import cn.com.scitc.dao.PaidTypesDao;
import cn.com.scitc.model.Paid;
import cn.com.scitc.model.Paidtypes;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/paid/edit")
public class PaidEditServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            PaidTypesDao paidTypesDao = new PaidTypesDao();
            List<Paidtypes> list = paidTypesDao.findAll();

            Integer id = Integer.parseInt(req.getParameter("id"));
            PaidDao paidDao = new PaidDao();
            Paid paid = paidDao.findById(id);
            req.setAttribute("model", paid);
            req.setAttribute("paidtypes", list);
            req.getRequestDispatcher("/WEB-INF/paid/edit.jsp").forward(req, resp);
        }
        catch (NumberFormatException er) {
            System.out.println("er: " + er.getMessage());
        }
    }
}
